﻿using diary.POCO;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace diary
{
    /// <summary>
    /// Interaction logic for BestView.xaml
    /// </summary>
    public partial class BestView : UserControl
    {
        private Best _best;
        private List<SongControl> bestSongsList = new List<SongControl>();
        private List<AlbumControl> bestAlbumList = new List<AlbumControl>();
        private List<MovieControl> bestMoviesList = new List<MovieControl>();
        private List<BookControl> bestBooksList = new List<BookControl>();
        private List<EventControl> bestEventsList = new List<EventControl>();
        private List<TelevisionControl> bestTvList = new List<TelevisionControl>();

        public BestView()
        {
            InitializeComponent();

            for (int i=0; i<15; i++)
            {
                SongControl bestsong = new SongControl();
                bestsong.Width = 1200;
                bestsong.Name = "BestSong"+i;
                BestSongs.Items.Add(bestsong);
                bestSongsList.Add(bestsong);

                AlbumControl bestalbum = new AlbumControl();
                bestalbum.Width = 1200;
                bestalbum.Name = "BestAlbum" + i;
                BestAlbums.Items.Add(bestalbum);
                bestAlbumList.Add(bestalbum);

                MovieControl bestmovie = new MovieControl();
                bestmovie.Width = 1200;
                bestmovie.Name = "BestMovie" + i;
                BestMovies.Items.Add(bestmovie);
                bestMoviesList.Add(bestmovie);

                BookControl bestbook = new BookControl();
                bestbook.Width = 800;
                bestbook.Name = "BestBook" + i;
                BestBooks.Items.Add(bestbook);
                bestBooksList.Add(bestbook);

                EventControl bestevent = new EventControl();
                bestevent.Width = 800;
                bestevent.Name = "BestEvent" + i;
                BestEvents.Items.Add(bestevent);
                bestEventsList.Add(bestevent);

                TelevisionControl besttv = new TelevisionControl();
                besttv.Width = 800;
                besttv.Name = "BestTV" + i;
                BestTVShows.Items.Add(besttv);
                bestTvList.Add(besttv);
            }

            for (int col=0; col<4; col++)
            {
                for (int row=0; row<4; row++)
                {
                    Image img = new Image();
                    img.Name = "img" +col + "_" + row;
                    img.Stretch = Stretch.Fill;
                    Grid.SetColumn(img, col);
                    Grid.SetRow(img, row);
                    Pictures.Children.Add(img);
                }
            }
        }

        public void SetBest(Best best, string monthlabel)
        {
            _best = best;
            int count = 0;
            foreach(Song song in _best.Songs)
            {
                if (count < bestSongsList.Count)
                {
                    bestSongsList[count].Song = song;
                }
                count++;
            }
            lblSongs.Content = "Best songs of " + monthlabel;

            count = 0;
            foreach (Album album in _best.Albums)
            {
                if (count < bestAlbumList.Count)
                {
                    bestAlbumList[count].Album = album;
                }
                count++;
            }

            count = 0;
            foreach (Movie movie in _best.Movies)
            {
                if (count < bestMoviesList.Count)
                {
                    bestMoviesList[count].Movie = movie;
                }
                count++;
            }

            count = 0;
            foreach (Book book in _best.Books)
            {
                if (count < bestBooksList.Count)
                {
                    bestBooksList[count].Book = book;
                }
                count++;
            }

            count = 0;
            foreach (Event devent in _best.Events)
            {
                if (count < bestEventsList.Count)
                {
                    bestEventsList[count].Event = devent;
                }
                count++;
            }

            count = 0;
            foreach (Television tvshow in _best.Television)
            {
                if (count < bestTvList.Count)
                {
                    bestTvList[count].Television = tvshow;
                }
                count++;
            }

            count = 0;
            foreach (Picture pic in _best.Pictures)
            {
                if (count < Pictures.Children.Count)
                {
                    Image childControl = (Image)Pictures.Children[count];
                    childControl.Source = new BitmapImage(new Uri(pic.File));
                }
                count++;
            }
        }

        private void btnSongUp_Click(object sender, RoutedEventArgs e)
        {
            if (BestSongs.SelectedItem != null)
            {
                MessageBox.Show("GOING UP!");
            }
        }

        private void btnSongDown_Click(object sender, RoutedEventArgs e)
        {
            if (BestSongs.SelectedItem != null)
            {
                MessageBox.Show("GOING DOWN...");
            }
        }
    }
}
